<template>
  <el-collapse v-model="activeNames">
    <el-collapse-item v-for="item in dataList" :key="item.Id" :name="item.Instancenodeid">
      <template slot="title">
        <span style="display:block;width:100px">{{ item.Nodename }}</span> <i class="header-icon el-icon-info" />
        开始时间：{{ item.Begindate }}  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;完成时间： {{ item.Enddate }}
      </template>
      <LoadForm ref="loadform" :vue-name="item.vueName" :src="item.Formkey" :event="item.event" :data="item.Inputdata" />
    </el-collapse-item>
  </el-collapse>
</template>
<script>
import LoadForm from './loadform'
import { LowercaseKeys } from '@/utils/index'
import { getInstanceNode } from '@/api/workflowprocess'
export default {
  components: {
    LoadForm
  },
  // eslint-disable-next-line vue/require-prop-types
  props: ['id', 'instanceId'],
  data() {
    return {
      activeNames: [],
      dataForm: {
        Id: 0
      },
      dataList: []
    }
  },
  created() {
    this.initd(this.id, this.instanceId)
  },
  methods: {
    initd(id, instanceId) {
      const _this = this
      this.activeNames = []
      this.$nextTick(() => {
        // const _option = this.$refs.loadform.$options
        const parameter = {
          'InstanceNodeId': id,
          'InstanceId': instanceId,
          'CandidateId': '1'
        }
        getInstanceNode(parameter).then((item) => {
          if (item.data) {
            item.data.forEach((data, index) => {
              if (index < 2) {
                this.activeNames.push(data.Instancenodeid)
              }
              data.vueName = data.Processcode + '_' + data.Instancenodeid
              if (!data.Formkey) {
                data.Formkey = 'myworkflow/todo/components/approve'
                if (!data.Inputdata) {
                  const param = {}
                  param.id = id
                  data.Inputdata = param
                } else {
                  if (data.Inputdata && typeof (data.Inputdata) === 'string') {
                    data.Inputdata = JSON.parse(data.Inputdata)
                  }
                  data.Inputdata.id = id
                  data.Inputdata = LowercaseKeys(data.Inputdata)
                }
                data.event = {}
                data.event.close = function() {
                  _this.$emit('close')
                }
              } else {
                if (data.Inputdata && typeof (data.Inputdata) === 'string') {
                  data.Inputdata = JSON.parse(data.Inputdata)
                }
              }
            })
          }
          this.dataList = item.data
        })
      })
    }
  }
}
</script>
